package com.djsearch.ui;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.djsearch.R;
import com.djsearch.adapter.JiuDianListViewAdapter;
import com.djsearch.bean.PlaneTicket;
import com.djsearch.bean.WineShop;
import com.djsearch.controller.JSONResp;

/**
 * 酒店页面
 * @author chenyang2
 *
 */
public class JiuDianActivity extends BaseActivity {
	private Context mContext;
	private Button backBtn;
	private ListView jiuDianListView;
	private List<WineShop> wineShopList;
	RelativeLayout jiuDianTitleLayout;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.jiudian_layout);
		mContext = this;
		wineShopList = new ArrayList<WineShop>();
		getHouseData();
		//得到屏幕的分辨率
		getDisPlayMetrics();
		//初始化主界面
		initView();
		//初始化主界面相关点击事件
		initOnClick();
		//
		initHandler();
	}

	@Override
	void initHandler() {
		// TODO Auto-generated method stub
		
	}

	@Override
	void initView() {
		// TODO Auto-generated method stub
		backBtn = (Button)findViewById(R.id.jiuDianBackBtn);
		jiuDianListView = (ListView)findViewById(R.id.jiuDianListView);
	    jiuDianTitleLayout = (RelativeLayout)findViewById(R.id.jiuDianTopTitle);
	    JiuDianListViewAdapter jiuDianListViewAdapter = new JiuDianListViewAdapter(mContext,wineShopList);
	    jiuDianListView.setAdapter(jiuDianListViewAdapter);
	}

	@Override
	void initOnClick() {
		// TODO Auto-generated method stub
		backBtn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				startActivity(mContext, SearchJiuDianActivity.class, 1);
			}
		});
		
		jiuDianListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				startActivity(mContext, JiuDianDetailsActivity.class, 0);
			}
		});
		
	}

	
	private void getHouseData() {
		Intent intent = getIntent();   
	    Object[] cobjs = (Object[])intent.getSerializableExtra("data");  
	    for (int i = 0; i < cobjs.length; i++) {   
	    	WineShop winShop = (WineShop)cobjs[i];   
	    	wineShopList.add(winShop);   
	       } 
	}
	
	/**
	 * 点击返回键
	 */
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			startActivity(mContext, SearchJiuDianActivity.class, 1);
		}
		return false;
	}

	@Override
	void getDataToResolve(JSONResp response) {
		// TODO Auto-generated method stub
		
	}
}
